using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace TextSupport
{
	// Text frame model
	public class TextFrame
	{
		internal RectangleF _extent;
		public RectangleF Extent
		{
			get { return _extent; }
			set { _extent = value; }
		}

		internal string _text;
		public string Text
		{
			get 
			{ 
				return buildString(); 
			}
		}

		public TextFrame()
		{
		}

		List<TextLine> _lines = new List<TextLine>();
		internal List<TextLine> Lines
		{
			get
			{
				return _lines;
			}
		}

		string buildString()
		{
			StringBuilder sb = new StringBuilder();
			foreach (TextLine line in _lines)
			{
				if (sb.Length > 0)
					sb.Append(" ");

				sb.Append(line.Text);
			}

			return sb.ToString();
		}

		public SizeF MeasureExtent(IEditSurface surface, Graphics g)
		{
			// TODO: Word Wrap
			return g.MeasureString(_text, surface.GetDefaultFont(), (int)_extent.Width);
		}

		public void UpdateLayout()
		{
			_lines.Clear();
			_lines.Add(new TextLine(_text));
		}
	}
}
